# -*- coding: utf-8 -*-
"""
@File: extract_files.py
@Time: 2023/01/02 09:27
@Author: 鹄望潇湘
@desc: 解压zip和rar压缩包，原本为doc, docx, pdf格式的文件则直接复制至目标文件夹

"""
import os
import shutil
import rarfile
import zipfile

source_path = ""
target_path = ""

for file in os.listdir(source_path):
    if file.endswith(("doc", "docx", "pdf")):
        shutil.move(os.path.join(source_path, file), os.path.join(target_path, file))
    elif file.endswith("zip"):
        rf = zipfile.ZipFile(os.path.join(source_path, file))
        for file1 in rf.namelist():
            if file1 == "__MACOSX":
                continue
            info = rf.getinfo(file1)
            rf.extract(info, target_path)

        pass
    elif file.endswith("rar"):
        rf = rarfile.RarFile(os.path.join(source_path, file))
        for file1 in rf.namelist():
            if file1 == "__MACOSX":
                continue
            info = rf.getinfo(file1)
            rf.extract(info, target_path)

    else:
        print("Warning: 意外的文件格式{}， 该文件未做任何处理".format(file))


